package model.DAO;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.Entity.Web.VoteOption;
import model.Entity.Web.VoteOptionPK;

import org.springframework.stereotype.Repository;

@Repository("VoteOptionDAO")
public class VoteOptionDAO extends GenericDAO {
	
	public List<VoteOption> findAll(){
		return super.findAll(VoteOption.class);
	}
	
	public List<VoteOption> findByVoteID(Integer voteID){
		Map<String, Integer> paramMap = new HashMap<String, Integer>();
		paramMap.put("voteId", voteID);
		return super.findByNamedQuery(VoteOption.class, "findByVoteId", paramMap);
	}
	
	public void updateVote(Integer voteId, Integer optionId){
		VoteOptionPK voteOptionPK = new VoteOptionPK();
		voteOptionPK.setVoteId(voteId);
		voteOptionPK.setOptionId(optionId);
		VoteOption voteOption = super.findByKey(VoteOption.class, voteOptionPK);
		System.out.println(voteOption);
		voteOption.setResult(new Integer(voteOption.getResult().intValue() + 1));
		voteOption = super.mergeEntity(voteOption);
		System.out.println(voteOption);
	}

}
